#include "../src/huffman/huffman.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(int argc, const char *argv[])
{
    int ret = 0;
    char *src = "I love HelloWorld!";

    // 创建霍夫曼树
    htTree *codeTree = fhuffmanTree.buildTree(src);
    // 存放字符的编码
    hlTable *codeTable = fhuffmanTree.buildTable(codeTree);

    // 编码
    char encode[1024] = {0};

    fhuffmanTree.encode(codeTable, src, encode);
    printf("\n源字符串 %s 的\n霍夫曼编码为 %s\n", src, encode);

    // 解码
    char decode[1024] = {0};
    fhuffmanTree.decode(codeTree, "11101111001001100", decode);
    printf("源编码 %s 的霍夫曼解码为 %s\n", "11101111001001100", decode);

    fhuffmanTree.destroyTree(codeTree);
    fhuffmanTree.destroyTable(codeTable);

    printf("system exited with return code %d\n", ret);
    // getchar();

    return ret;
}
